package us.gaaoc.framework.dao;

import java.util.List;

import org.hibernate.Query;

import us.gaaoc.framework.model.OrganizationAddress;
import us.gaaoc.framework.model.Organizations;



/**
 * Home object for domain model class Organizations.
 * @see us.gaaoc.framework.model.Organizations
 * @author Hibernate Tools
 */
public class OrganizationsDAOHibernate extends GenericHibernateDAO<Organizations, String, OrganizationsDAO>
implements  OrganizationsDAO{

	protected OrganizationsDAOHibernate() {}

	public Organizations findOrgByName(String orgName) {
		Query q = getSession().createQuery("from Organizations o where o.name = ? ");
		q.setString(0, orgName);
		List result = q.list();
		if (result!=null && !result.isEmpty()){
			return (Organizations)result.get(0);
		}else
			return null;
	}

	/* (non-Javadoc)
	 * @see us.gaaoc.framework.dao.OrganizationsDAO#findOrganization(us.gaaoc.framework.model.Organizations, java.lang.String)
	 */
	public Organizations findOrganization(Organizations orgFound, String street1) {
		//Query q = this.getSession().createQuery("from Organizations o where o.organization = ? and oa.streetFullText = ?");
		Query q = this.getSession().createQuery("from Organizations o, Address a where o.uuid = ? and a.streetFullText = ?");
		
		//q.setEntity(0, orgFound.getUuid());
		q.setString(0, orgFound.getUuid());
		q.setString(1, street1);
		List result = q.list();
		if (result!=null && !result.isEmpty()){
			//return (Organizations)result.get(0);
			return (Organizations)result.get(0);
		}else
			return null;
	}
	
}